﻿#include "GraphicsVacuumPumpItem.h"
#include <QPen>
#include <QBrush>
#include <QPainter>
GraphicsVacuumPumpItem::GraphicsVacuumPumpItem() {}

void GraphicsVacuumPumpItem::setState(bool on)
{
    m_state = on;
    update();
}

QRectF GraphicsVacuumPumpItem::boundingRect() const
{
    return QRectF(-51, -51, 102, 102);
}

QPointF GraphicsVacuumPumpItem::keyPoint(int i)
{
    return QPointF(0, -50);
}

void GraphicsVacuumPumpItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
    m_state = !m_state;
    emit pumpStateChanged(m_state);
    update();
}

void GraphicsVacuumPumpItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QBrush brushOn(Qt::darkGreen), brushOff(Qt::darkGray);

    QPen pen(Qt::black);
    pen.setWidth(3);

    painter->setPen(pen);
    painter->drawEllipse(QRect(-50, -50, 100, 100));
    painter->drawLine(QLine(-12, 48, -37, -33));
    painter->drawLine(QLine(12, 48, 37, -33));

    if(m_state)
    {
        painter->setBrush(brushOn);
        painter->drawEllipse(QRect(-25, -25, 50, 50));
    }
    else
    {
        painter->setBrush(brushOff);
        painter->drawEllipse(QRect(-25, -25, 50, 50));
    }
}
